package com.zft.userwalletmanager.infrastructure.common.utils;


import com.zft.userwalletmanager.infrastructure.common.enums.ResultCode;
import com.zft.userwalletmanager.infrastructure.common.exception.BizException;
import org.apache.commons.lang3.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

public class DateFormatUtil {
    public static long time;
    public static SimpleDateFormat format;
    public static String dateFormat(Date date) {
        if (Objects.isNull(date)) {
            throw new BizException(ResultCode.PARAM_ERROR);
        }
        time = date.getTime();
        format = new SimpleDateFormat("yyyy年MM月dd日 hh:mm:ss");
        return format.format(time);
    }

    public static Date dateParse(String date) throws ParseException {
        if (StringUtils.isBlank(date)) {
            throw new BizException(ResultCode.PARAM_ERROR);
        }
        format = new SimpleDateFormat("yyyy年MM月dd日");
        Date date1 = format.parse(date);
        time = date1.getTime();
        Date date2 = new Date(time);
        return date2;
    }
}
